<template>
  <div class="container">
    <van-nav-bar
      class="page-nav-bar"
      title="专题详情"
      left-arrow
      @click-left="onClickLeft"
    />
    <div id="p1" class="content"></div>
    <div class="message">
      <p class="mtitle">
        精选留言
        <van-icon name="chat-o" @click="tomsg" />
      </p>
      <div id="mbody">
        <div class="mcell" v-for="(obj, index) in msg" :key="index">
          <div class="header">
            <span class="text">
              <img src="@/assets/头像.png" alt="" />{{
                obj.user_info.nickname
              }}</span
            >
            <span class="time"> {{ obj.add_time }}</span>
          </div>
          <div class="body">{{ obj.content }}</div>
        </div>
        <div class="getmore" @click="getmore">查看更多</div>
      </div>
    </div>
    <p class="ptitle">专题推荐</p>
    <van-cell
      v-for="(obj, index) in list"
      :key="index"
      class="item"
      @click="todetail(obj.id)"
    >
      <van-image class="img" :src="obj.scene_pic_url"></van-image>
      <div class="title">{{ obj.title }}</div>
      <div class="subtitle">{{ obj.subtitle }}</div>
    </van-cell>
  </div>
</template>

<script>
import { subdetail, subject, getmsg } from "@/api/subject";
export default {
  data() {
    return {
      msg: [],
      list: [],
      detail: null,
      dataj: {
        page: 1,
        size: 5,
      },
      mesdata: {
        valueId: this.$route.query.id,
        typeId: 1,
        page: 1,
        size: 10,
        showType: 0,
      },
    };
  },
  created() {
    this.grtdetail();
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    getmore() {
      this.$router.push({
        path: "/message",
        query: {
          id: this.$route.query.id,
        },
      });
    },
    todetail(id) {
      this.$router.push({
        path: "/subject/subdetail",
        query: {
          id: id,
        },
      });
      this.$router.go(0);
    },
    tomsg() {
      this.$router.push({
        path: "/message/add",
        query: {
          id: this.$route.query.id,
        },
      });
    },
    async grtdetail() {
      try {
        const { data } = await subdetail(this.$route.query.id);
        const { data: data1 } = await subject(this.dataj);
        const { data: data2 } = await getmsg(this.mesdata);
        this.list = data1.data.data;
        if (data2.data.data.length > 0) {
          this.msg = data2.data.data;
        } else {
          document.getElementById("mbody").innerHTML =
            '<img src="http://122.51.249.55:8360/static/dist/static/img/liu.b3713707.png" alt=""  style="width: 100%;"/>';
        }

        document.getElementById("p1").innerHTML = data.data.content;
      } catch (err) {
        console.log(err);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding-top: 90px;
  #p1 {
    display: flex;
    flex-direction: column;
  }
  .message {
    background-color: #fff;
    padding-top: 20px;
    .mtitle {
      margin: 50px 0px;
      font-size: 32px;
      text-align: left;
      padding: 0px 60px;
      .van-icon {
        float: right;
      }
    }
    .getmore {
      margin-top: 60px;
      text-align: center;
      font-size: 28px;
      color: #666;
      margin-bottom: 30px;
    }
  }
  #mbody{
    padding-bottom: 1px;
  }
  .mcell {
    padding: 0 50px;
    margin-bottom: 40px;
    .header {
      display: flex;
      justify-content: space-between;
      font-size: 28px;
      margin-bottom: 10px;
      img {
        width: 70px;
        height: 70px;
        border-radius: 50%;
        margin-right: 30px;
        vertical-align: middle;
      }
      .text{
        line-height: 50px;
      }
      .time {
        font-size: 20px;
        color: #666;
        line-height: 50px;
      }
    }
    .body {
      border-bottom: 1px solid #999;
      padding-bottom: 30px;
      font-size: 30px;
      height: auto;
      margin-top: 20px;
      color: #777;
    }
  }
  .item {
    display: flex;
    flex-direction: column;
    .img {
      width: 100%;
      height: 400px;
    }
    .title {
      font-size: 32px;
      text-align: center;
    }
    .price {
      text-align: center;
      color: red;
    }
    .subtitle {
      font-size: 24px;
      text-align: center;
      height: 100px;
      color: #666;
    }
  }
  .ptitle {
    margin: 50px 0px;
    font-size: 34px;

    text-align: center;
  }
  .page-nav-bar {
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
  }
}
</style>
